#include "ScoreboardLayer.h"
#include "Debug.h"
#include <stdlib.h> 

ScoreboardLayer::ScoreboardLayer(void)
{
}


ScoreboardLayer::~ScoreboardLayer(void)
{
}


ScoreboardLayer * ScoreboardLayer::create()
{
    ScoreboardLayer * pRet = new ScoreboardLayer();
    if (pRet && pRet->init())
    {
        Debug::show(pRet);
    }
    else
    {
        CC_SAFE_DELETE(pRet);
    }
    return pRet;
}

bool ScoreboardLayer::init()
{
    bool bRet = false;
    do
    {
        CC_BREAK_IF(! CCLayer::init());

        pLabel = CCLabelTTF::create("0", "Arial", 24);
        CC_BREAK_IF(! pLabel);
        this->addChild(pLabel);
        pLabel->setPosition(CCPointZero);
        bRet = true;
    }
    while (0);
    return bRet;
}

void ScoreboardLayer::setScoreboard(int n)
{
    scoreboard = n;
    changScoreboard();
}

void ScoreboardLayer::addScoreboard(int n)
{
    setScoreboard(scoreboard + n);
}

void ScoreboardLayer::changScoreboard()
{
	char  pString[25];
	sprintf(pString, "%d",scoreboard); 
	 pLabel->setString(pString);
    CCSize tSize = this->getContentSize();
    CCSize lSize = pLabel->getContentSize();
    
    pLabel->setPosition(ccp(tSize.width * 0.5, lSize.height * 0.5));
}